<?php 
defined('_JEXEC') or die('Restricted access');

$listOrder = $this->lists['order']; 
$listDirn = $this->lists['order_Dir'];
?>
<script type="text/javascript" src="<?php echo JURI::base(true)?>/components/com_wrd/assets/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
<!--
	function changeToPickUp(id){
		date = jQuery('#pick_up_date_'+id).val();
		jQuery.ajax({
			url: "index.php?option=com_wrd&task=changetopickup",
			type: "POST",
			data: 'id='+id+'&date='+date,
			success: function (res) {
				jQuery('#title_pickup').css('width','5%');
				jQuery('#date_pickup_value_'+id).html(date) ;
				jQuery('#div_date_pickup_'+id).html('<img width="16" height="16" src="<?php echo JURI::base().'components/com_wrd/assets/images/approve.png' ;?>" />');
			}
		});
	}
	function showDatePickUpDiv(divId){
		jQuery(document).ready(function() {
			jQuery.noConflict();
			jQuery('.div_date_pickup').css('display','none');
			jQuery('#'+divId).css('display','');
			jQuery('#title_pickup').css('width','15%');
		});
	}
//-->
</script>
<style>
<!--
	.pick_up_date, .calendar{
		float: left !important;
	}
	.pick_up_date{
		margin-left: 5px !important;
	}
	.calendar{
		margin: 0 5px !important;
	}
	.go{
		cursor: pointer;
	}
	.go:hover{
		background-color: #d0d0d0 ;
	}	
-->
</style>
<form  id="adminForm"  action="<?php echo JRoute::_('index.php?option=com_wrd') ; ?>" method="post" name="adminForm" >
	<table class="adminlist">
		<thead>
			<tr>
				<th class="title" width="10%">
                	<?php echo JHTML::_('grid.sort',  'Name', 'p.f_name', $listDirn, $listOrder ); ?>
               	</th>
               	<th class="title" width="80px">
                	<?php echo JHTML::_('grid.sort',  'Member ID', 'p.member_id', $listDirn, $listOrder ); ?>
               	</th>
                <th nowrap="nowrap" width="110px">
				   	<?php echo JHTML::_('grid.sort',  'Phone', 'p.phone', $listDirn, $listOrder ); ?>
				</th>
				<th nowrap="nowrap" width="10%">
				   	<?php echo JHTML::_('grid.sort',  'Job', 'p.job',$listDirn, $listOrder ); ?>
				</th> 
				<th nowrap="nowrap" width="10%">
				   	<?php echo JHTML::_('grid.sort',  'Company name', 'p.company_name', $listDirn, $listOrder ); ?>
				</th>
				<th nowrap="nowrap" width="10%">
				   	<?php echo JHTML::_('grid.sort',  'Created By', 'p.created_id', $listDirn, $listOrder ); ?>
				</th>
				<th nowrap="nowrap" width="10%">
				   	<?php echo JHTML::_('grid.sort',  'Created Date', 'p.created_date', $listDirn, $listOrder ); ?>
				</th>
				<th nowrap="nowrap" width="10%">
				   	<?php echo JHTML::_('grid.sort',  'Modify date', 'p.modify_date', $listDirn, $listOrder ); ?>
				</th>
				<th id='title_pickup' nowrap="nowrap" width="5%">
				   	<?php echo JHTML::_('grid.sort',  'Pick up', 'p.pick_up_date', $listDirn, $listOrder ); ?>
				</th>
				<th nowrap="nowrap" width="10%">
				   	<?php echo JHTML::_('grid.sort',  'Pick up date', 'p.pick_up_date', $listDirn, $listOrder ); ?>
				</th>
			</tr>
		</thead>
		<tbody>
		<?php
           $k = 0;
			for ($i=0, $n= count( $this->items ); $i < $n; $i++):
				$row = &$this->items[$i];
				$checked 	= JHTML::_('grid.checkedout',   $row, $i);
	            $canChange	= $user->authorise('core.edit.state', 'com_wrd.reports.'.$row->id);
				$published 	= JHTML::_('jgrid.published', $row->published, $i,'reports.', $canChange,'cb');
				?>
				<tr class="<?php echo "row$k"; ?>"  >
	                <td>
						<a href="#edit">
							<?php if($row->f_name != '' && $row->l_name != ''):?>
								<?php echo $row->f_name." ".$row->l_name; ?>
							<?php else :?>
								<?php echo $row->email; ?>
							<?php endif;?>
						</a>
					</td>
					<td>
						<?php echo $row->member_id; ?>
					</td>
					<td>
						<?php echo $row->phone; ?>
					</td>
					<td>
						<?php 
							if($row->job != 'other'){
								if(!empty($row->job_name)){ 
									echo $row->job_name;
								}
							}else{
								echo $row->o_job ;
							} 
						?>
					</td>
					<td>
						<?php echo $row->company_name; ?>
					</td>
					<td>
						<?php echo $row->created_per; ?>
					</td>
					<td>
						<?php echo $row->created_date; ?>
					</td>
					<td>
						<?php echo $row->modify_date; ?>
					</td>
					<td id='div_date_pickup_<?php echo $row->id ;?>'>
						<?php 
							if(empty($row->pick_up_date) || ($row->pick_up_date =='0000-00-00')):	
						?>
							<a style='float: left;' href='javascript:void(0)' onclick="showDatePickUpDiv('date_pickup_<?php echo $row->id ;?>')"><img id='aprrove' width='16' height='16' src="<?php echo JURI::base().'components/com_wrd/assets/images/waiting_approve.png' ;?>" alt='Non Pick Up' title='Click here to change to Pick Up' /></a>
							<div style='float: left; display: none;' class='div_date_pickup' id='date_pickup_<?php echo $row->id ;?>'>
								<?php
									echo JHTML::_( 'calendar', '', 'pick_up_date_'.$row->id, 'pick_up_date_'.$row->id, '%Y-%m-%d', 'size="15" class="pick_up_date"' );
								?>
								<input class='go' title='Go' type='button' value="Go" onclick="changeToPickUp(<?php echo $row->id ;?>)" />
							</div>
						<?php else:?>
							<img width='16' height='16' src="<?php echo JURI::base().'components/com_wrd/assets/images/approve.png' ;?>" />
						<?php endif;?>
					</td>
					<td id='date_pickup_value_<?php echo $row->id ;?>'>
						<?php  
							if(!empty($row->pick_up_date) && $row->pick_up_date !='0000-00-00'){
								echo $row->pick_up_date; 
							}
						?>
					</td>
				</tr>
				<?php
	            $k = 1 - $k;
			endfor ;
		?>
		</tbody>
		<tfoot>
			<tr>
				<td colspan="16">
                    <?php
                         echo $this->pagination->getListFooter();
                    ?>
                </td>
			</tr>
		</tfoot>
	</table>
	<table style = " width: 100% ; ">
		<tr>
			<td align="center">
				<a href="#exprot" id="export">Export to excel</a>
			</td>
		</tr>
	</table>
	
	<input type="hidden" name="controller" value="reports" />
	<input type="hidden" name="option" value="com_wrd" />
	<input type="hidden" name="task" value="view" />
    <input type="hidden" name="filter_order" value="<?php echo $this->lists['order']; ?>" />
    <input type="hidden" name="filter_order_Dir" value="<?php echo $this->lists['order_Dir']; ?>" />
	<?php echo JHTML::_( 'form.token' ); ?>
</form>